from pathlib import Path

from data.download import download_cifar10, extract_tar
from data.extract import extract_images
from data.utils import verify_structure


def prepare_data():
    """数据准备主入口"""
    # 1. 下载数据
    tar_path = download_cifar10()

    # 2. 解压数据
    raw_dir = extract_tar(tar_path)

    # 3. 提取为图像文件
    extract_images(raw_dir)

    # 4. 验证结果
    if verify_structure(Path("data/processed")):
        print("Data preparation completed successfully!")
    else:
        raise RuntimeError("Data preparation failed - invalid directory structure")


if __name__ == '__main__':
    prepare_data()
